<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
<input type="button" value="没怀孕">
<input type="button" value="没怀孕">
<input type="button" value="没怀孕">
<input type="button" value="没怀孕">
<input type="button" value="没怀孕">
<script>
    var btnObj = document.getElementsByTagName("input");
    //循环遍历所有按钮
    for (var i = 0; i < btnObj.length; i++) {
        btnObj[i].onclick = function () {
            for (var j = 0; j < btnObj.length; j++) {
                btnObj[j].value = "没怀孕";
            }
            this.value = "怀孕了"; //this不能写成btnObjp[i],因为btnObj在外面已经执行完毕
        };
    }
</script>
</body>
</html>